package netty.v2;


import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.string.StringDecoder;

public class NettyClient {
    public static void main(String[] args) {
        Bootstrap bootstrap = new Bootstrap();
        bootstrap.group(new NioEventLoopGroup())
                .channel(NioSocketChannel.class)
                .handler(new ChannelInitializer<NioSocketChannel>() {
                    @Override
                    protected void initChannel(NioSocketChannel ch) throws Exception {
                        //ch.pipeline().addLast(new StringDecoder());
                        ch.pipeline().addLast(new ClientFirstHandler());
                    }
                });
        bootstrap.connect("192.168.128.228", 8001).addListener(future -> {
            if(future.isSuccess()){
                System.out.println("client connect success");
            }else{
                System.out.println("client connect failure");
            }
        });

    }
}
